package com.lenovo.manufacture.module;

import android.widget.RadioButton;
import android.widget.RadioGroup;
import com.beardedhen.androidbootstrap.BootstrapButton;
import com.lenovo.manufacture.BaseActivity;
import com.lenovo.manufacture.R;
import com.lenovo.manufacture.annotation.Layout;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

public class Module12 extends BaseActivity {

    @BindView(R.id.radioGroup1)
    RadioGroup radioGroup1;
    @BindView(R.id.radioGroup)
    RadioGroup radioGroup;
    @BindView(R.id.button)
    BootstrapButton button;
    @BindView(R.id.btn_line1)
    RadioButton btnLine1;
    @BindView(R.id.btn_line2)
    RadioButton btnLine2;
    @BindView(R.id.btn_line3)
    RadioButton btnLine3;
    @BindView(R.id.btn_pos1)
    RadioButton btnPos1;
    @BindView(R.id.btn_pos2)
    RadioButton btnPos2;
    @BindView(R.id.btn_pos3)
    RadioButton btnPos3;
    @BindView(R.id.btn_pos4)
    RadioButton btnPos4;

    @Layout(value = R.layout.activity_module12,title = "创建学生生产线")
    public void init() {
        initCheck();
        async(apiService.getAllUserLine(), data -> {
            for (Map<String, String> userLine : data.getData()) {
                switch (Integer.valueOf(userLine.get("pos"))) {
                    case 0:
                        btnPos1.setEnabled(false);
                        break;
                    case 1:
                        btnPos2.setEnabled(false);
                        break;
                    case 2:
                        btnPos3.setEnabled(false);
                        break;
                    case 3:
                        btnPos4.setEnabled(false);
                        break;
                }
            }
        });
    }


    @OnClick(R.id.button)
    public void onViewClicked() {
        if (json.get("lineId") == null || json.get("pos") == null) {
            showMsg("请选择生产线和位置");
            return;
        }

        async(apiService.createLine(json), data -> {
            showMsg("创建成功");
        });
    }

    private void initCheck() {
        btnLine1.setOnCheckedChangeListener((buttonView, isChecked) -> json.put("lineId", 1));
        btnLine2.setOnCheckedChangeListener((buttonView, isChecked) -> json.put("lineId", 2));
        btnLine3.setOnCheckedChangeListener((buttonView, isChecked) -> json.put("lineId", 3));
        btnPos1.setOnCheckedChangeListener((buttonView, isChecked) -> json.put("pos", 0));
        btnPos2.setOnCheckedChangeListener((buttonView, isChecked) -> json.put("pos", 1));
        btnPos3.setOnCheckedChangeListener((buttonView, isChecked) -> json.put("pos", 2));
        btnPos4.setOnCheckedChangeListener((buttonView, isChecked) -> json.put("pos", 3));

    }

}